package com.lht.cozyCloud.bee.utils;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.http.MethodType;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author lht
 * @version 1.0
 * @description: 短信请求工具
 * @date 2025/1/7 8:49
 */
@Component
public class RequestUtil {

    private static final String ALIYUN_SMS_DOMAIN = "dysmsapi.aliyuncs.com";
    private static final String ALIYUN_SMS_VERSION = "2017-05-25";
    private static final String ALIYUN_SMS_ACTION = "SendSms";

    public static CommonRequest aliyunRequest(String phone, Map<String, Object> param)
    {
        CommonRequest request = new CommonRequest();
        //request.setProtocol(ProtocolType.HTTPS);
        request.setMethod(MethodType.POST);
        request.setDomain(ALIYUN_SMS_DOMAIN);
        request.setVersion(ALIYUN_SMS_VERSION);
        request.setAction(ALIYUN_SMS_ACTION);

        //手机号
        request.putQueryParameter("PhoneNumbers", phone);
        //签名名称
        request.putQueryParameter("SignName", "阿里云短信测试");  // 暂时使用官方提供
        //模板code
        request.putQueryParameter("TemplateCode", "SMS_154950909");  //  暂时使用官方提供

//        //验证码  使用json格式   {"code":"123456"}
//        Map<String, Object> param = new HashMap();
//        param.put("code", code);
        request.putQueryParameter("TemplateParam", JSONObject.toJSONString(param));
        return request;
    }
}
